import React from 'react';
import {
  View,
  Text,
  StyleSheet,
  TouchableOpacity,
  ActivityIndicator,
} from 'react-native';

interface ActionBarProps {
  actions: Array<{
    id: string;
    label: string;
    icon?: string;
    onPress: () => void;
    disabled?: boolean;
    loading?: boolean;
  }>;
  focusedActionIndex: number;
  isActionFocused: boolean;
}

export const ActionBar: React.FC<ActionBarProps> = ({
  actions,
  focusedActionIndex,
  isActionFocused,
}) => {
  const getActionStyle = (index: number) => {
    const action = actions[index];
    const isFocused = isActionFocused && focusedActionIndex === index;
    
    return [
      styles.actionButton,
      action.disabled && styles.disabledAction,
      isFocused && styles.focusedAction,
    ];
  };

  const getActionTextStyle = (index: number) => {
    const action = actions[index];
    const isFocused = isActionFocused && focusedActionIndex === index;
    
    return [
      styles.actionText,
      action.disabled && styles.disabledActionText,
      isFocused && styles.focusedActionText,
    ];
  };

  return (
    <View style={styles.container}>
      {actions.map((action, index) => (
        <TouchableOpacity
          key={action.id}
          style={getActionStyle(index)}
          onPress={action.onPress}
          disabled={action.disabled}
          hasTVPreferredFocus={index === 0 && isActionFocused}
          tvParallaxProperties={{
            enabled: true,
            shiftDistanceX: 2.0,
            shiftDistanceY: 2.0,
            tiltAngle: 0.05,
            magnification: 1.1,
          }}
        >
          {action.loading ? (
            <ActivityIndicator size="small" color="#ffffff" />
          ) : (
            <Text style={getActionTextStyle(index)}>
              {action.icon && `${action.icon} `}
              {action.label}
            </Text>
          )}
        </TouchableOpacity>
      ))}
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    paddingHorizontal: 20,
    paddingVertical: 15,
    backgroundColor: '#1a1a1a',
    borderTopWidth: 1,
    borderTopColor: '#444',
    gap: 20,
  },
  actionButton: {
    paddingHorizontal: 20,
    paddingVertical: 12,
    borderRadius: 25,
    backgroundColor: '#4a90e2',
    borderWidth: 2,
    borderColor: 'transparent',
    minWidth: 100,
    alignItems: 'center',
    justifyContent: 'center',
  },
  disabledAction: {
    backgroundColor: '#666666',
    opacity: 0.6,
  },
  focusedAction: {
    borderColor: '#ffffff',
    backgroundColor: '#5a9ee2',
  },
  actionText: {
    color: '#ffffff',
    fontSize: 16,
    fontWeight: 'bold',
  },
  disabledActionText: {
    color: '#cccccc',
  },
  focusedActionText: {
    color: '#ffffff',
  },
}); 